package com.ziyun.erp.modules.report.service.impl;

import io.renren.common.utils.R;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import com.ziyun.erp.modules.report.dao.ErpReportDao;
import com.ziyun.erp.modules.report.entity.ErpReportEntity;
import com.ziyun.erp.modules.report.service.ErpReportService;


@Service("erpReportService")
public class ErpReportServiceImpl extends ServiceImpl<ErpReportDao, ErpReportEntity> implements ErpReportService {

    @Autowired
    private ErpReportDao erpReportDao;

    @Value("${ureport.url}")
    private String ureportUrl;
    @Value("${ureport.desigerUrl}")
    private String desigerUrl ;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        int totalCount = this.baseMapper.getqueryCount();
        int current = Integer.valueOf((String) params.get("page"));
        int size = Integer.valueOf((String) params.get("limit"));
        params.put("offset", (current - 1) * size);
        params.put("limit", size);
        List<ErpReportEntity> list = erpReportDao.getQueryList(params);
        return new PageUtils(list, totalCount, size, current);
    }

    /**
     * 标记删除数据
     * @param reId
     */
    @Override
    public void deleteUpdate(Integer reId) {
        baseMapper.deleteUpdate(reId);
    }

    /**
     * 查询报表list
     * @param type
     * @return
     */
    @Override
    public R querylist(String type) {
        List<ErpReportEntity> erpReportList = baseMapper.querylist(type);
        return R.ok().put("erpReportList", erpReportList);
    }

    @Override
    public R getUreportName(Integer uId) {
        String reportName = baseMapper.getUreportName(uId);

        reportName = ureportUrl + reportName;
        return R.ok(reportName);
    }

    @Override
    public R ureportMaplist() {
        List<Map<String,Object>> ureportList = baseMapper.ureportMaplist();
        return R.ok().put("ureportList",ureportList);
    }

    @Override
    public R getUreportDesigner() {
        return R.ok(desigerUrl);
    }

    @Autowired
	private BusProperties busProperties;
    
	@Override
	public void test() {
//        RefreshGoodsCacheEvent event = RefreshGoodsCacheEvent.builder().source(this).build();
//		EventBusPusher.syncPost(event);
	}

}
